#include "qpushbuttonwidget.h"

QPushButtonWidget::QPushButtonWidget(QWidget *parent):QPushButton( parent ), type(ButtonType::TYPE_DEFAULT) {

    setButtonType( ButtonType::TYPE_DEFAULT );
}
QPushButtonWidget::~QPushButtonWidget()
{
    // 析构函数通常空即可
}
void QPushButtonWidget::setWidth(int width) {
    this->setFixedWidth( width );
}
void QPushButtonWidget::setHeight(int height) {
    this->setFixedHeight( height );
}

void QPushButtonWidget::setButtonType(ButtonType type) {
    this->type = type;
    QString baseStyle = "QPushButton{font-size:14px; padding:6px 12px; border-radius:4px; ";
    QString typeStyle;

    switch(type){
    case ButtonType::TYPE_DEFAULT:
        typeStyle = "background-color:#fff; color:#000; border:1px solid #ccc;"
                    "}"
                    "QPushButton:hover{background-color:#fff; color:#000; border:1px solid #999;}";
        break;
    case ButtonType::TYPE_PRIMARY:
        typeStyle = "background-color:#007bff; color:#fff; border:1px solid #007bff;"
                    "}"
                    "QPushButton:hover{background-color:#0069d9; color:#fff; border:1px solid #0062cc;}";
        break;
    case ButtonType::TYPE_DANGER:
        typeStyle = "background-color:#dc3545; color:#fff; border:1px solid #dc3545;"
                    "}"
                    "QPushButton:hover{background-color:#c82333; color:#fff; border:1px solid #bd2130;}";
        break;
    }
    setStyleSheet( baseStyle + typeStyle );
}
void QPushButtonWidget::setTextValue(const QString &text) {
    this->setText(text);
}
void QPushButtonWidget::setTextColor(const QColor &color) {
    //设置文字颜色
    QString style = QString("color: %1;").arg(color.name());
    this->setStyleSheet( style );
}
void QPushButtonWidget::setStyle(const QString &style) {
    this->setStyleSheet( style );
}

